﻿<!DOCTYPE html>
<html>
<head>
    <title>JS Objects Exercise 4</title>
    <link href="styles/js-console.css" rel="stylesheet" />
</head>
<body>
    <h1>Function that checks if a given object contains a given property.</h1>
    <div id="js-console"></div>
    <script src="scripts/js-console.js"></script>
    <script>
        function hasProperty(obj, strProp) {
            for (var prop in obj) {
                if (prop == strProp) {
                    return true;
                }
            }

            return false;
        }

        var obj1 = {
            name: "hmm",
            length: 5
        };
        var obj2 = {
            name: "hmm",
            size: 5
        };

        var hasProp1 = hasProperty(obj1, "length");
        var hasProp2 = hasProperty(obj2, "length");

        jsConsole.writeLine("Has property: " + hasProp1 + " " + hasProp2);

    </script>
</body>
</html>
